<template>
  <div class="general">
    <div class="g-language">
      <div class="g-language-box">
        <div class="g-language-content flex items-center">
          <div class="g-l-text">
            {{ $t("setup.commonInfo.platformLanguage") }}
          </div>
          <el-select v-model="curLanguage" @change="handleChangeLanguage">
            <el-option
              v-for="item in languageOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
              <div>
                <div>{{ item.label }}</div>
                <div style="color: #8492a6; font-size: 13px">
                  {{ curLanguage == "en" ? item.explainEn : item.explain }}
                </div>
              </div>
            </el-option>
          </el-select>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      curLanguage: null, // 当前平台语言
    };
  },
  computed: {
    ...mapState({
      languageOptions: (state) => state.systemStyle.languageOptions,
    }),
  },
  mounted() {
    this.curLanguage = this.$i18n.locale;
  },
  methods: {
    handleChangeLanguage(val) {
      localStorage.setItem("platformLanguage", val);
      location.reload(true);
    },
  },
};
</script>

<style lang="scss" scoped>
.general {
  .g-language {
    position: relative;
    transition: opacity 0.3s;
    .g-language-box {
      padding: 32px 0;
      .g-language-content {
        margin-bottom: 16px;
        .g-l-text {
          padding-right: 20px;
          line-height: 24px;
          font-size: 16px;
          font-weight: 600;
        }
      }
    }
  }
}
</style>